<template>
  <el-container style="padding:10px 1rem;">
    <header>
      <h1 style=" width:100%; text-align: center;">问卷调查系统哈哈哈哈哈哈</h1>
      <p>
        2020年2月24日，第十三届全国人大常委会第十六次会议通过《关于全面禁止非法野生动物交易、革除滥食野生动物陋习、切实保障人民群众生命健康安全的决定》。
        关于野生动物和人畜共患病，你了解多少呢？
      </p>
      <el-divider></el-divider>
    </header>
    <el-main>
      <div class="question" style="padding: 15px;" v-for="(item,index) in parentList" :key="index">
        <div class="title">
          {{item.title}}
          <span>{{ item.options==2?"":item.options==1?"(多选)":"(单选)" }}</span>
        </div>
        <div class="matrix">
          <ul>
            <li v-for="answer in item.answerList" :key="answer.id">
              <div v-if="answer.options==0">
                <input type="radio" />
                <span>{{answer.title}}</span>
              </div>
              <div v-if="answer.options==1">
                <input type="checkbox" />
                <span>{{answer.title}}</span>
              </div>
              <div v-if="answer.options==2">
                <span>
                  {{answer.title}}
                  <input type="text" />
                </span>
              </div>
            </li>
          </ul>
        </div>
      </div>
    </el-main>
    <el-footer>
      <p>Copyright 个人博客模板 All Rights Reserved. 备案号：津ICP备19004899 公安备案号 12011602000311</p>
    </el-footer>
  </el-container>
</template>

<script>
import { listSurveys } from "@/api/webIndex";
export default {
  name: "webIndex",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 题目信息表格数据
      questionList: [],
      parentList: [],
      answerList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 1000,
        surveysNo: "S201900001"
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询题目信息列表 */
    getList() {
      this.loading = true;
      listSurveys(this.queryParams).then(response => {
        this.questionList = response.rows;
        //分开问题与答案
        this.questionList.forEach((item, index, array) => {
          if (item.type === 0) {
            this.parentList.push(item);
          } else {
            this.answerList.push(item);
          }
        });
        //答案写入到对应的问题里面
        this.parentList.forEach((item, index, array) => {
          var questionNo = item.questionNo;
          item.answerList = [];
          this.answerList.forEach((answer, index, array) => {
            var questionParentId = answer.questionParentId;
            if (questionNo == questionParentId) {
              item.answerList.push(answer);
            }
          });
        });
        this.total = response.total;
        this.loading = false;
      });
    }
  }
};
</script>

<style rel="stylesheet/scss" lang="scss">
footer {
  background: #373d41;
  width: 100%;
  border-top: #00c1de 10px solid;
  color: #73777a;
  font-size: 14px;
}
.title {
  width: 100%;
  padding: 0 10px;
}

.matrix {
  width: 100%;
  margin: 0;
  padding: 0 10px;
}
.matrix ul {
  list-style: none;
}
.matrix ul li {
  line-height: 30px;
}
</style>
